/*
 * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "cmsis_os2.h"
#include "ohos_init.h"

#define FLAGS_MSK1 0x00000001U

osEventFlagsId_t g_eventFlagsId; // event flags id

int Example_EventChect(uint32_t EVENT)
{
 if(EVENT == osFlagsErrorTimeout)
 {
  printf(">>>Example Event read event time out!\r\n");
  return -1;
 }
 if(EVENT == osFlagsErrorParameter){
  printf(">>>Example Event read event Parameter error!\rin");
  return -1;
 }

 return 0;
}
void Example_Event(void)
{
 uint32_t event;
 event = osEventFlagsWait(g_eventFlagsId, 0x00000400, osFlagsWaitAll, 100);
 event = osEventFlagsWait(g_eventFlagsId, 0x00008400, osFlagsWaitAll, 100);
 if(Example_EventChect(event) == 0){
  printf(">>>Example Event Wait success!\r\n");
 }
}
void Example_TaskEntry(void)
{
 g_eventFlagsId = osEventFlagsNew(NULL);
 osThreadAttr_t attr;
 attr.name = "Example_Event";
 attr.stack_size = 1024;
 attr.priority = osPriorityNormal;
 osThreadNew(Example_Event, NULL, &attr);
 osEventFlagsSet(g_eventFlagsId,0x00000400);
 osEventFlagsSet(g_eventFlagsId,0x00008000);
 osDelay(300);
 osEventFlagsDelete(g_eventFlagsId);
}

APP_FEATURE_INIT(Example_TaskEntry);
